import { Injectable } from '@angular/core'
import { HttpClientService } from 'src/app/common/httpClient/http'
import { CoolLocalStorage } from 'src/app/common/coolStorage/cool-local-storage'

@Injectable({
  providedIn: 'root'
})
export class OprbarService {
  constructor(private storage: CoolLocalStorage, private http: HttpClientService) {}

  toggleFavorite(type, id, favorite, callback, errBack?) {
    let opr = favorite ? 'Remove' : 'Add'
    let url = `/House1/Json/${this.upperFirstLetter(type)}FollowService.svc/${opr}`
    let reqdata = {
      zone: this.storage.getItem('zone')
    }
    reqdata[type] = id
    this.http.post(reqdata, url, callback, errBack)
  }
  upperFirstLetter(str) {
    if (str.length === 0) {
      return ''
    } else {
      let first_l = str.substring(0, 1)
      let first_u = first_l.toUpperCase()
      return first_u + str.substring(1, str.length)
    }
  }
}
